
  <div class="main layui-clear"> 
   <h2 class="page-title">注册</h2> 
   <div class="layui-form layui-form-pane"> 
    <form method="post"> 
     <div class="layui-form-item"> 
      <label for="L_email" class="layui-form-label">邮箱</label> 
      <div class="layui-input-inline"> 
       <input id="L_email" name="email" required="" lay-verify="email" autocomplete="off" class="layui-input" type="text" /> 
      </div> 
      <div class="layui-form-mid layui-word-aux">
       将会成为您唯一的登入名
      </div> 
     </div> 
     <div class="layui-form-item"> 
      <label for="L_username" class="layui-form-label">昵称</label> 
      <div class="layui-input-inline"> 
       <input id="L_username" name="nikename" required="" lay-verify="nikename" autocomplete="off"  class="layui-input" type="text" value="" /> 
      </div> 
     </div> 
     <div class="layui-form-item"> 
      <label for="L_pass" class="layui-form-label">密码</label> 
      <div class="layui-input-inline"> 
       <input id="password" name="password" required="" lay-verify="password" autocomplete="off" class="layui-input" type="password" value="" /> 
      </div> 
      <div class="layui-form-mid layui-word-aux">
       6到16个字符
      </div> 
     </div> 
     <div class="layui-form-item"> 
      <label for="L_repass" class="layui-form-label">确认密码</label> 
      <div class="layui-input-inline"> 
       <input id="L_repass" name="repass" required="" lay-verify="repassword" autocomplete="off" class="layui-input" type="password" /> 
      </div> 
     </div> 
     <div class="layui-form-item"> 
      <label for="L_vercode" class="layui-form-label">人类验证</label> 
      <div class="layui-input-inline"> 
       <input id="L_vercode" name="vercode" required="" lay-verify="vercode" placeholder="请回答后面的问题" autocomplete="off" class="layui-input" type="text" /> 
      </div> 
      <div class="layui-form-mid"> 
       <span style="color: #c00;"> <?php echo $res[0]['vercode'] ?></span> 
      </div> 
     </div> 
     <div class="layui-form-item"> 
      <button class="layui-btn" lay-filter="register" lay-submit="">立即注册</button> 
     </div> 
     <div class="layui-form-item fly-form-app"> 
      <span>或者直接使用社交账号快捷注册</span> 
      <a href="http://fly.layui.com:8098/app/qq" onclick="layer.msg('正在通过QQ登入', {icon:16, shade: 0.1, time:0})" class="iconfont icon-qq" title="QQ登入"></a> 
      <a href="http://fly.layui.com:8098/app/weibo/" onclick="layer.msg('正在通过微博登入', {icon:16, shade: 0.1, time:0})" class="iconfont icon-weibo" title="微博登入"></a> 
     </div> 
    </form> 
   </div>
  </div>



<!-- js库 -->
 <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
 <script type="text/javascript" src='__PUBLIC__/layui/layui.js'></script>
 <script type="text/javascript" >
 // 插件的规定写法
  layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form()
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
 
  //自定义验证规则
  form.verify({
  
    email:function(value){    //绿色的名字是lay-verify属性的值
    var is_error=0;
      $.ajax({
        url: "{:U('home/register/checkemail')}",    //请求地址
        type: 'POST',             //请求方式
        async: false,             //false为同步方式，true是异步方式
        dataType: 'json',         //请求格式
        data: {email: value},     //发送参数
        success:function(data) {         
             if(data.error ==1 ){  
                 is_error=data.info;
             } 
          } ,
        error : function(data) {   
             alert("异常,ajax没有接收到数据！") 
        } 
      })
    if (is_error!=0) {      
        return is_error;    
        //如果不ruturn东西给email的函数，会默认通过，返回一些东西给他就不通过,返回的内容就是弹出类的内容
      } 
    },
    
    nikename:function(value){
      var is_error=0;
      $.ajax({
        url: "{:U('home/register/checknikename')}",    //请求地址
        type: 'POST',             //请求方式
        async: false,              //false为同步方式，true是异步方式
        dataType: 'json',         //请求格式
        data: {nikename: value},     //发送参数
        success:function(data) {         
             if(data.error ==1 ){  
                 is_error=data.info;
             } 
          },
        error : function(data) {   
             alert("异常,ajax没有接收到数据！")
        } 
      })
      if (is_error!=0) {      
        return is_error;    
      }
    },
    password:function(value){
      var is_error=0;
      $.ajax({
        url: "{:U('home/register/checkpassword')}",    //请求地址
        type: 'POST',             //请求方式
        async: false,              //false为同步方式，true是异步方式
        dataType: 'json',         //请求格式
        data: {password: value},     //发送参数
        success:function(data) {         
             if(data.error ==1 ){  
                 is_error=data.info;
             } 
          },
        error : function(data) {   
             alert("异常,ajax的password没有接收到数据！")
        } 
      })
      if (is_error!=0) {      
        return is_error;    
      }
    },
    repassword: function(value){
          password = $('#password').val();
          if(password!=value){
              return "密码不一致";
          }
    },
    vercode:function(value){
      var is_error=0;
      $.ajax({
        url: "{:U('home/register/checkcode')}",    
        type: 'POST',             
        async: false,              
        dataType: 'json',         
        data: {vercode: value},     
        success:function(data) {         
             if(data.error ==1 ){  
                 is_error=data.info;
             } 
          },
        error : function(data) {   
             alert("ajax的验证 没有接收到数据！")
        } 
      })
      if (is_error!=0) {      
        return is_error;    
      }
    },



  });
  //监听提交
  form.on('submit(register)', function(data){
         $.ajax({
            url: "{:U('home/register/add')}",
            type: 'POST',
            dataType: 'json',
            async: false,
            data: data.field,
            success:function(response){
                    if(response.error==0){
                        layer.confirm(response.info, {
                          btn: ['确定'] //按钮
                        }, function(){
                           location.replace("{:U('home/login/index')}");
                        });
                    }
                }
            })
        
        return false;
      });
  
  



});








 </script>
</html>